﻿#include"BinSearch.h"
void test1()
{
	Key::BSTree<int> t;
	int a[] = { 8, 3, 1, 10, 1, 6, 4, 7, 14, 13 };
	for (auto& e : a)
	{
		t.Insert(e);
	}
	t.InOrder();
	for (auto& e : a)
	{
		t.Erase(e);
		t.InOrder();
	}
	t.InOrder();
}

void test2()
{
	Key_Value::BSTree<string,string> dict;
	//BSTree<string, string> copy = dict;
	dict.Insert("left", "左边");
	dict.Insert("right", "右边");
	dict.Insert("insert", "插入");
	dict.Insert("string", "字符串");
	string str;
	while (cin >> str)
	{
		auto ret = dict.Find(str);
		if (ret)
		{
			cout << "->" << ret->_value << endl;
		}
		else
		{
			cout << "没有要查找的单词哟~" << endl;
		}
	}
}

void test3()
{
	string arr[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜",
"苹果", "香蕉", "苹果", "香蕉" };
	Key_Value::BSTree<string, int> countTree;
	for (const auto& str : arr)
	{
		// 先查找⽔果在不在搜索树中
		// 1、不在，说明⽔果第⼀次出现，则插⼊<⽔果, 1>
		// 2、在，则查找到的结点中⽔果对应的次数++
		//BSTreeNode<string, int>* ret = countTree.Find(str);
		auto ret = countTree.Find(str);
		if (ret == NULL)
		{
			countTree.Insert(str, 1);
		}
		else
		{
			ret->_value++;
		}
	}
	
	string arr1[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜",
"苹果", "香蕉", "苹果", "香蕉","哈密瓜","榴莲","柚子","樱桃"};
	Key_Value::BSTree<string, int>CopyTree2;
	for (const auto& str : arr1)
	{
		// 先查找⽔果在不在搜索树中
		// 1、不在，说明⽔果第⼀次出现，则插⼊<⽔果, 1>
		// 2、在，则查找到的结点中⽔果对应的次数++
		//BSTreeNode<string, int>* ret = countTree.Find(str);
		auto ret = CopyTree2.Find(str);
		if (ret == NULL)
		{
			CopyTree2.Insert(str, 1);
		}
		else
		{
			ret->_value++;
		}
	}
	 countTree=CopyTree2;
	countTree.InOrder();
}
int main()
{
	test1();
	return 0;
}